package com.hb.trade.api.routine.config.pay;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

/**
 * 微信支付参数模型
 */
@Setter
@Getter
@ToString
public class WeixinPayBody {
    /**
     * 商品描述
     */
    private String body;
    /**
     * 商品总价(单位: 元)
     */
    private String actualAmount;
    /**
     * 订单号
     */
    private String outOrderNo;

    public String getOutOrderNo() {
        if (StrUtil.isEmpty(outOrderNo)) {
            return newTradeNo();
        }
        return outOrderNo;
    }

    private Long sectionId;
    private Integer feeType;

    public static String newTradeNo() {
        return newTradeNo(null);
    }
    public static String newTradeNo(String orderHeader) {
        String randomStr = RandomUtil.randomNumbers(7);
        if (StrUtil.isEmpty(orderHeader)){
            orderHeader = "";
        }
        return orderHeader + DateUtil.format(DateUtil.date(), "yyyyMMddHHmmssSSS") + randomStr;
    }
}
